package jdbc;

import jdbc.common.InputUtil;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;

public class RegUserDemo {
    public static void main(String[] args) throws  Exception{
        Connection conn = DBUtil.getConnection();
        System.out.println("与数据库连接成功！");
        UserInfo user = InputUtil.getInputObject(new UserInfo(),"注册新用户");
//        System.out.println(user);

//        Class.forName("com.mysql.cj.jdbc.Driver");
//
//        Connection conn = DriverManager.getConnection(
//                "jdbc:mysql://localhost:3306/tedu?characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai&rewriteBatchedStatements=true",
//                "root",
//                "root");

        Statement stat = conn.createStatement();
        String sql = "INSERT INTO userinfo(username,password,nickname,age) "+
                "VALUES ('" + user.getUsername()+"','"+
                user.getPassword()+"','"+
                user.getNickname()+"','"+
                user.getAge()+"')";
        int num = stat.executeUpdate(sql);
        System.out.println(num>0?"加入成功":"加入失败");
        conn.close();
    }
}
